package cn.pn.project.controller;

import cn.pn.project.client.comment.FindFeign;
import cn.pn.project.client.comment.FindFeign;
import cn.pn.project.client.commodity.CommodityFeign;
import cn.pn.project.client.user.UserFeign;
import cn.pn.project.common.Page;
import cn.pn.project.common.RedisUtils;
import cn.pn.project.pojo.comment.Comment;
import cn.pn.project.pojo.comment.Find;
import cn.pn.project.pojo.commodity.Commodity;
import cn.pn.project.pojo.user.User;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/api")
public class FindController {
    @Autowired
    private FindFeign findFeign;
    @Autowired
    private UserFeign userFeign;
    @Autowired
    private CommodityFeign commodityFeign;
    @Autowired
    private RedisUtils redisUtils;
    @RequestMapping(value = "/p/listFindComment")
    public String listFindComment(HttpServletRequest request)throws Exception{
        List<Comment> commentList=findFeign.selectFind();
        List<Find> findList=new ArrayList<>();
        for (int i=0;i<commentList.size();i++){
            Find find=new Find();
            find.setUser(userFeign.findUserById(commentList.get(i).getUserId()));
            find.setCommodity(commodityFeign.findCommodityAllMessage(commentList.get(i).getCommodityId()));
            find.setComment(commentList.get(i));
            findList.add(find);
        }
        System.out.println("/**************************************************************/");
        System.out.println("-----------consumer的/comment/listFindComment方法-----------");
        return JSON.toJSONString(findList, true);
    }
}
